#-----------------------------------------------------------
# adoberdr.pl
# Plugin for Registry Ripper
# Parse Adobe Reader MRU keys
#
# Change history
#   20100218 - added checks for versions 4.0, 5.0, 9.0
#   20091125 - modified output to make a bit more clear
#
# References
#
# Note: LastWrite times on c subkeys will all be the same,
#       as each subkey is modified as when a new entry is added
#
# copyright 2010 Quantum Analytics Research, LLC
#-----------------------------------------------------------
package adobe_pdf;
use strict;
use DateTime::Format::WindowsFileTime;
use Time::gmtime;

require "functions.pl";

my %config = (hive          => "NTUSER\.DAT",
              hasShortDescr => 1,
              hasDescr      => 0,
              hasRefs       => 0,
              osmask        => 22,
              version       => 20100218);

sub getConfig{return %config}
sub getShortDescr {
	return "Gets user's Adobe Reader cRecentFiles values";
}
sub getDescr{}
sub getRefs {}
sub getHive {return $config{hive};}
sub getVersion {return $config{version};}

sub chgDateTimeFormat
#change Mon Aug  1 02:51:31 2011 to 2011-08-01_02:51:31
{
	my $data = $_[0];
	(my $weekDay, my $month, my $day, my $time, my $year)
	= split(/\s+/, $data);
	my @tmp = ($weekDay, $month,$day, $time, $year);
	#print("$month".length($month)."\n");
	my $month2;
	my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
		"Sep", "Oct", "Nov", "Dec");
	for(my $count = 0; $count <= 11; $count++){
		if( $months[$count] eq $month){
			$month2 = $count+1;
			last;
		}
	}
	if($month2 < 10){
		$month2 = "0".$month2;
	}
	if($day < 10){
		$day = "0".$day;
	}
	return  ($year."/".$month2."/".$day."_".$time);
}

my $VERSION = getVersion();


sub pluginmain {
	my $class = shift;
	my $ntuser = shift;
	#::logMsg("Launching adoberdr v.".$VERSION);
	my $reg = Parse::Win32Registry->new($ntuser);
	my $root_key = $reg->get_root_key;
	#::rptMsg("Adoberdr v.".$VERSION);
# First, let's find out which version of Adobe Acrobat Reader is installed
	my $version;
	my $tag = 0;
	my @versions = ("4\.0","5\.0","6\.0","7\.0","8\.0","9\.0");
	foreach my $ver (@versions) {
		my $key_path = "Software\\Adobe\\Adobe Acrobat\\".$ver."\\AVGeneral\\cRecentFiles";
		if (defined($root_key->get_subkey($key_path))) {
			$version = $ver;
			$tag = 1;
		}
	}

	if ($tag) {
		#::rptMsg("Adobe Acrobat Reader version ".$version." located.");
		my $key_path = "Software\\Adobe\\Adobe Acrobat\\".$version."\\AVGeneral\\cRecentFiles";
		my $key = $root_key->get_subkey($key_path);
		if ($key) {
			my %arkeys;
			my @subkeys = $key->get_list_of_subkeys();
			if (scalar @subkeys > 0) {
				foreach my $s (@subkeys) {
					my $num = $s->get_name();
					my $data = $s->get_value('tDIText')->get_data();
					$num =~ s/^c//;
					$arkeys{$num}{lastwrite} = $s->get_timestamp();
					$arkeys{$num}{data} = $data;
				}
				foreach my $k (sort keys %arkeys) {
					if($k == 1){
						my $time = chgDateTimeFormat("".CORE::gmtime($arkeys{$k}{lastwrite}));
						::rptMsg(
						UTC_to_UTF8($time).",REG ,(host) ,(user) ,Adobe Acrobat ,".$arkeys{$k}{data} );
					}else{
						::rptMsg(" ,REG ,(host) ,(user) ,Adobe Acrobat ,".$arkeys{$k}{data} );
					}
				}
			}
			else {
				::logMsg($key_path." has no subkeys.");
			}
		}
		else {
			::logMsg("Could not access ".$key_path);
		}
	}
	else {
		::logMsg("Adobe Acrobat Reader version not found.");
	}
}

1;